/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ifrr.gepro.acesso.dao;

import br.ifrr.gepro.util.BaseDao;
import br.ifrr.gepro.util.Conexao;
import br.ifrr.gepro.util.DAOException;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author rafael
 */
public class UsuarioDao extends BaseDao {

    private Session session = null;
    private Transaction transaction = null;

    public Object selecionarPorLogin(String login) throws DAOException {
        try {
            session = Conexao.getInstace();
            Object obj;
            obj = session.createQuery("from " + getClasseVO() + " where userlogin = '" + login + "'").uniqueResult();
            session.flush();
            return obj;
        } catch (HibernateException e) {
            throw new DAOException(e);
        } finally {
            try {
                if (transaction != null) {
                    if (!transaction.wasCommitted()) {
                        transaction.rollback();
                    }
                    if (session != null) {
                        session.close();
                    }
                }
            } catch (HibernateException e1) {
                throw new DAOException(e1);
            }
        }
    }
}
